<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>添加满减送</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="{__STATIC__}/layuiAdmin/layui/css/layui.css" rel="stylesheet">
    <link href="{__STATIC__}/layuiAdmin/adminui/dist/css/admin.css" rel="stylesheet">
    <link href="{__STATIC__}/layuiAdmin/style/style.css" rel="stylesheet">
    <style>
        html {background: #fff;padding-top: 20px;}
    </style>
</head>
<body>
    <div class="layui-form">
        <div class="layui-form-item">
            <label class="layui-form-label"><span>*</span> 名称：</label>
            <div class="layui-input-inline">
                <input type="text" name="m_title" lay-verify="required" placeholder="请输入名称" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">如：满200减10元</div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span>*</span> 活动类型：</label>
            <div class="layui-input-inline w180">
                <select name="m_type" lay-filter="m_type">
                    <option value="0" selected>按金额</option>
                    <option value="1">按件数</option>
                </select>
            </div>
            <div class="layui-form-mid layui-word-aux">满N元或满N件时优惠。</div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span>*</span> 优惠门槛：</label>
            <div class="layui-input-inline w180">
                <input type="text" name="m_min_price" lay-verify="number" value="0.00" placeholder="请输入优惠门槛" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux"><label id="span_type">元</label></div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span>*</span> 优惠内容：</label>
            <div class="layui-input-inline w180">
                <select name="m_send_type" lay-filter="m_send_type">
                    <option value="0" selected>直减</option>
                    <option value="1">折扣</option>
                    <option value="2">送积分</option>
                    <option value="3">送优惠券</option>
                </select>
            </div>
            <div class="layui-form-mid layui-word-aux"></div>
        </div>
        <div class="layui-form-item" id="send_type_0">
            <label class="layui-form-label"><span>*</span> 直减金额：</label>
            <div class="layui-input-inline w180">
                <input type="text" name="m_send_price" lay-verify="number" value="0.00" placeholder="请输入直减金额" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">元</div>
        </div>
        <div class="layui-form-item" id="send_type_1" style="display: none;">
            <label class="layui-form-label"><span>*</span> 折扣数量：</label>
            <div class="layui-input-inline w180">
                <input type="text" name="m_send_rebate" lay-verify="number" value="10.0" placeholder="请输入折扣数量" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">折，如：8.5</div>
        </div>
        <div class="layui-form-item" id="send_type_2" style="display: none;">
            <label class="layui-form-label"><span>*</span> 积分数量：</label>
            <div class="layui-input-inline w180">
                <input type="text" name="m_send_integral" lay-verify="number" value="0" placeholder="请输入积分数量" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">分</div>
        </div>
        <div class="layui-form-item" id="send_type_3" style="display: none;">
            <label class="layui-form-label"><span>*</span> 选择优惠券：</label>
            <div class="layui-input-inline w180">
                <select name="m_send_coupon_id">
                    <option value="0" selected>请选择优惠券</option>
                    {volist name="couponList" id="vo"}
                    <option value="{$vo.id}">{$vo.title}</option>
                    {/volist}
                </select>
            </div>
            <div class="layui-form-mid layui-word-aux">请先添加内部优惠券</div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label"><span>*</span> 活动时间：</label>
            <div class="layui-input-inline w180">
                <input type="text" class="layui-input" lay-verify="required" name="b_date" id="b_date" placeholder="开始时间" autocomplete="off">
            </div>
            <div class="layui-form-mid">
                -
            </div>
            <div class="layui-input-inline w180">
                <input type="text" class="layui-input" lay-verify="required" name="e_date" id="e_date" placeholder="结束时间" autocomplete="off">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">使用范围：</label>
            <div class="layui-input-inline w180">
                <select name="m_use_type" lay-filter="m_use_type">
                    <option value="0" selected>全部商品</option>
                    <option value="1">指定商品</option>
                </select>
            </div>
            <div class="layui-form-mid layui-word-aux">可指定商品。</div>
        </div>
        <div class="layui-form-item" id="span_goods" style="display: none">
            <label class="layui-form-label">选择商品：</label>
            <div class="layui-input-block">
                <div id="goods_ctr"></div>
                <div class="upload_btn" onclick="select_goods();"></div>
            </div>
        </div>
        <div class="layui-form-item layui-hide">
            <input type="button" lay-submit lay-filter="LAY-submit" id="LAY-submit" value="确认">
        </div>
    </div>
</body>
</html>

<script src="{__STATIC__}/jquery/jquery.min.js"></script>
<script src="{__STATIC__}/layuiAdmin/layui/layui.js"></script>
<script>
    layui.use(function(){
        let $ = layui.$;
        let laydate = layui.laydate;
        let form = layui.form;

        laydate.render({
            elem: '#b_date'
            ,type: 'datetime'
            ,trigger: 'click'
        });

        laydate.render({
            elem: '#e_date'
            ,type: 'datetime'
            ,trigger: 'click'
        });

        /* 监听select */
        form.on('select(m_type)',function (data) {
            if(data.value==0){
                $("#span_type").html('元');
            }
            else {
                $("#span_type").html('件');
            }
        });

        form.on('select(m_send_type)',function (data) {
            $('#send_type_0').hide();
            $('#send_type_1').hide();
            $('#send_type_2').hide();
            $('#send_type_3').hide();
            $('#send_type_' + data.value).show();
        });

        form.on('select(m_use_type)',function (data) {
            if(data.value==0){
                $("#span_goods").hide();
            }
            else {
                $("#span_goods").show();
            }
        });
    });

    //选择商品
    function select_goods() {
        layer.open({
            type: 2,
            title: '选择商品',
            shadeClose: true,
            shade: false,
            area: ['90%', '90%'],
            content: "{:url('admin/goods/selectGoods')}"
        });
    }

    //选择商品后返回处理
    function call_back(id,title,pic,price) {
        layer.closeAll('iframe');
        let flag = 1;
        let $m_str = '';
        $m_str = $m_str + '<div class="slide_ctr" id="m_goods'+id+'">';
        $m_str = $m_str + '<div class="pic_del"><i class="layui-icon layui-icon-delete" onclick="removeGoods('+id+')"></i></div>';
        $m_str = $m_str + '<img src="'+ pic +'">';
        $m_str = $m_str + '<div class="slide_title">'+title+'</div>';
        $m_str = $m_str + '</div>';
        $m_str = $m_str + '<input type="hidden" name="m_goods[]" value="'+id+'">';
        let array = $("[name='m_goods[]']");
        for(let i = 0;i < array.length;i++) {
            let value = $(array[i]).val();
            if(id == value){
                flag = 0;
                break;
            }
        }
        if(flag) $('#goods_ctr').append($m_str);
    }
    //移除商品
    function removeGoods(id) {
        $("#m_goods"+id).remove();
    }
</script>